package command.client;

import client.ClientSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.User;

public class GetListOfUsersClient implements CommandClient {

    public GetListOfUsersClient() {
    }

    @Override
    public void execute(ClientSession clientSession, boolean isInvokedByTheServer) {
        try {
            if (isInvokedByTheServer) {
                ArrayList<User> userList = (ArrayList<User>) clientSession.getObjectInputStream().readObject();
                clientSession.getGUIChatPrincipal().updateAllUserList(userList);
            } else {
            }
        } catch (IOException | ClassNotFoundException ex) {
            Logger.getLogger(GetListOfUsersClient.class.getName()).log(Level.SEVERE,
                    "Error al recibir la lista de usuarios activos en el chat", ex);
        }
    }
}
